package com.dyz.LeetCodeforSwordFingerOffer;

public class DeleteNode18 {
    public ListNode deleteNode(ListNode head, int val) {
        //判断空节点,
        if(head==null){return null;}
        if(head.val==val){return head.next;}
        //双指针指向两个节点的前后
        ListNode temp = head;
        ListNode cur = head.next;
        while (cur!=null&cur.val!=val){
            temp = cur;
            cur = cur.next;
        }
        if(cur!=null){
            temp.next = cur.next;
        }
        return head;
    }

}
